// HSS.Forms.Docking.DockContent.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       DockContent.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
namespace HSS.Forms.Docking
{
	#region Using Directives
	using System;
	using System.ComponentModel;
	using System.Diagnostics.CodeAnalysis;
	using System.Drawing;
	using System.Windows.Forms;
	#endregion

	#region DockContent
	/// <summary>
	/// <para>DockContent derives from Form class. To use the DockPanel library, you can derive your 
	/// form from DockContent class, and implement your user interface in this class.</para>
	/// <para>NOTE: This Docking Feature is based in whole or in part on the DockPanelSuite library
	/// by Weifen Luo (c) 2004-05-28 and licensed under the MIT License and can be located on 
	/// SourceForge (http://sourceforge.net/projects/dockpanelsuite/)</para>
	/// </summary>
	/// <remarks>DockContent wraps all the properties, methods and events of DockContentHandler objects.</remarks>
	public class DockContent : Form, IDockContent
	{
		#region Events
		/// <summary>
		/// DockStateChanged Event
		/// </summary>
		[LocalizedCategory("Category_PropertyChanged")]
		[LocalizedDescription("Pane_DockStateChanged_Description")]
		public event EventHandler DockStateChanged
		{
			add { Events.AddHandler(DockStateChangedEvent, value); }
			remove { Events.RemoveHandler(DockStateChangedEvent, value); }
		}
		/// <summary>
		/// Fires the DockStateChanged event
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnDockStateChanged(EventArgs e)
		{
			EventHandler handler = (EventHandler)Events[DockStateChangedEvent];
			if (handler != null)
				handler(this, e);
		}
		private static readonly object DockStateChangedEvent = new object();
		#endregion

		#region Constructor
		/// <summary>
		/// ctor
		/// </summary>
		public DockContent()
		{
			_dockHandler = new DockContentHandler(this, new GetPersistStringCallback(GetPersistString));
			_dockHandler.DockStateChanged += new EventHandler(DockHandler_DockStateChanged);
			if (!this.IsDisposed)
				this.Enter += new EventHandler(DockContent_Enter);
		}
		#endregion

		#region Properties

		/// <summary>
		/// DockHandler
		/// </summary>
		[Browsable(false)]
		public DockContentHandler DockHandler
		{
			get { return _dockHandler; }
		} DockContentHandler _dockHandler = null;

		/// <summary>
		/// AllowEndUserDocking
		/// </summary>
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_AllowEndUserDocking_Description")]
		[DefaultValue(true)]
		public bool AllowEndUserDocking
		{
			get { return DockHandler.AllowEndUserDocking; }
			set { DockHandler.AllowEndUserDocking = value; }
		}

		/// <summary>
		/// DockAreas
		/// </summary>
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_DockAreas_Description")]
		[DefaultValue(DockAreas.DockLeft | DockAreas.DockRight | DockAreas.DockTop | DockAreas.DockBottom | DockAreas.Document | DockAreas.Float)]
		public DockAreas DockAreas
		{
			get { return DockHandler.DockAreas; }
			set { DockHandler.DockAreas = value; }
		}

		/// <summary>
		/// AutoHidePortion
		/// </summary>
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_AutoHidePortion_Description")]
		[DefaultValue(0.25)]
		public double AutoHidePortion
		{
			get { return DockHandler.AutoHidePortion; }
			set { DockHandler.AutoHidePortion = value; }
		}

		/// <summary>
		/// TabText
		/// </summary>
		[Localizable(true)]
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_TabText_Description")]
		[DefaultValue(null)]
		public string TabText
		{
			get { return DockHandler.TabText; }
			set { DockHandler.TabText = value; }
		}

		/// <summary>
		/// CloseButton
		/// </summary>
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_CloseButton_Description")]
		[DefaultValue(true)]
		public bool CloseButton
		{
			get { return DockHandler.CloseButton; }
			set { DockHandler.CloseButton = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public DockPanel DockPanel
		{
			get { return DockHandler.DockPanel; }
			set { DockHandler.DockPanel = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public DockState DockState
		{
			get { return DockHandler.DockState; }
			set { DockHandler.DockState = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public DockPane Pane
		{
			get { return DockHandler.Pane; }
			set { DockHandler.Pane = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public bool IsHidden
		{
			get { return DockHandler.IsHidden; }
			set { DockHandler.IsHidden = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public DockState VisibleState
		{
			get { return DockHandler.VisibleState; }
			set { DockHandler.VisibleState = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public bool IsFloat
		{
			get { return DockHandler.IsFloat; }
			set { DockHandler.IsFloat = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public DockPane PanelPane
		{
			get { return DockHandler.PanelPane; }
			set { DockHandler.PanelPane = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public DockPane FloatPane
		{
			get { return DockHandler.FloatPane; }
			set { DockHandler.FloatPane = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		protected virtual string GetPersistString()
		{
			return GetType().ToString();
		}
		/// <summary>
		/// 
		/// </summary>
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_HideOnClose_Description")]
		[DefaultValue(false)]
		public bool HideOnClose
		{
			get { return DockHandler.HideOnClose; }
			set { DockHandler.HideOnClose = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_ShowHint_Description")]
		[DefaultValue(DockState.Unknown)]
		public DockState ShowHint
		{
			get { return DockHandler.ShowHint; }
			set { DockHandler.ShowHint = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		public bool IsActivated
		{
			get { return DockHandler.IsActivated; }
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="dockState"></param>
		/// <returns></returns>
		public bool IsDockStateValid(DockState dockState)
		{
			return DockHandler.IsDockStateValid(dockState);
		}
		/// <summary>
		/// 
		/// </summary>
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_TabPageContextMenu_Description")]
		[DefaultValue(null)]
		public ContextMenu TabPageContextMenu
		{
			get { return DockHandler.TabPageContextMenu; }
			set { DockHandler.TabPageContextMenu = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[LocalizedCategory("Category_Docking")]
		[LocalizedDescription("DockContent_TabPageContextMenuStrip_Description")]
		[DefaultValue(null)]
		public ContextMenuStrip TabPageContextMenuStrip
		{
			get { return DockHandler.TabPageContextMenuStrip; }
			set { DockHandler.TabPageContextMenuStrip = value; }
		}
		/// <summary>
		/// 
		/// </summary>
		[Localizable(true)]
		[Category("Appearance")]
		[LocalizedDescription("DockContent_ToolTipText_Description")]
		[DefaultValue(null)]
		public string ToolTipText
		{
			get { return DockHandler.ToolTipText; }
			set { DockHandler.ToolTipText = value; }
		}

		#endregion

		#region Methods

		/// <summary>
		/// 
		/// </summary>
		public new void Activate()
		{
			DockHandler.Activate();
		}
		/// <summary>
		/// 
		/// </summary>
		public new void Hide()
		{
			DockHandler.Hide();
		}
		/// <summary>
		/// 
		/// </summary>
		public new void Show()
		{
			DockHandler.Show();
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="dockPanel"></param>
		public void Show(DockPanel dockPanel)
		{
			DockHandler.Show(dockPanel);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="dockPanel"></param>
		/// <param name="dockState"></param>
		public void Show(DockPanel dockPanel, DockState dockState)
		{
			DockHandler.Show(dockPanel, dockState);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="dockPanel"></param>
		/// <param name="floatWindowBounds"></param>
		[SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters")]
		public void Show(DockPanel dockPanel, Rectangle floatWindowBounds)
		{
			DockHandler.Show(dockPanel, floatWindowBounds);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="pane"></param>
		/// <param name="beforeContent"></param>
		public void Show(DockPane pane, IDockContent beforeContent)
		{
			DockHandler.Show(pane, beforeContent);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="previousPane"></param>
		/// <param name="alignment"></param>
		/// <param name="proportion"></param>
		public void Show(DockPane previousPane, DockAlignment alignment, double proportion)
		{
			DockHandler.Show(previousPane, alignment, proportion);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="floatWindowBounds"></param>
		[SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters")]
		public void FloatAt(Rectangle floatWindowBounds)
		{
			DockHandler.FloatAt(floatWindowBounds);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="paneTo"></param>
		/// <param name="dockStyle"></param>
		/// <param name="contentIndex"></param>
		public void DockTo(DockPane paneTo, DockStyle dockStyle, int contentIndex)
		{
			DockHandler.DockTo(paneTo, dockStyle, contentIndex);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="panel"></param>
		/// <param name="dockStyle"></param>
		public void DockTo(DockPanel panel, DockStyle dockStyle)
		{
			DockHandler.DockTo(panel, dockStyle);
		}


		private bool ShouldSerializeTabText()
		{
			return (DockHandler.TabText != null);
		}

		#endregion

		#region Event Handlers
		void DockHandler_DockStateChanged(object sender, EventArgs e)
		{
			OnDockStateChanged(e);
		}
		void DockContent_Enter(object sender, EventArgs e)
		{
			DockHandler.Activate();
		}
		#endregion
	}
	#endregion
}